<?php

namespace addons\helper\controller\wxapp;

use addons\helper\controller\wxapp\Base;
use app\admin\model\Admin;
use app\admin\model\SellerCode;
use fast\Tree;
use think\Session;

class Activity extends Base
{
    protected $searchFields = 'id';

    protected $noNeedRight = ['*'];
    protected $categorylist = [];

    public function _initialize()
    {
        parent::_initialize();
        $this->model = new \app\admin\model\Activity();
    }

    public function index()
    {
        //当前是否为关联查询
        $this->relationSearch = true;
        //设置过滤方法
        $this->request->filter(['strip_tags', 'trim']);
        list($where, $sort, $order, $offset, $limit) = $this->buildparams();

        if ($this->userId != get_addon_config('douyin')['super_id']) {
            $child = (new Admin())->getAgentChild($this->userId, 'shop_id');

            if ($child) {
                $this->model->where($this->model->getTable() . '.manystore_id', 'in', $child);
            } else {
                $shop_id = (new Admin())->where('id', $this->userId)->value('shop_id');
                if ($shop_id) {
                    $this->model->where($this->model->getTable() . '.manystore_id', $shop_id);
                }
            }
        }

        $list = $this->model
            ->with(['card', 'manystoreshop'])
            ->where($where)
            ->order($sort, $order)
            ->paginate($limit);



        foreach ($list as $row) {
            $row->getRelation('card')->visible(['title']);
            $row->getRelation('manystoreshop')->visible(['name']);
        }

        $result = array("total" => $list->total(), "rows" => $list->items());
        $this->success('ok', $result);
    }

    public function seller()
    {

        $id=$this->request->param('id');
        $row=$this->model->get($id);
        $baseurl = $this->request->domain()."/index.php";
        $ClientKey = config('site.ClientKey');
        $ClientSecret = config('site.ClientSecret');
        if ($ClientKey && $ClientSecret) {
            $url = "https://open.douyin.com/platform/oauth/connect/?client_key=" . $ClientKey . "&response_type=code&scope=user_info,video.create&redirect_uri={$baseurl}/index/index/seller/ids/{$id}";


        }

       $this->success('ok',compact('url','row'));

    }






}
